#pragma once

#include "..\Knowledge\KnowlTypeTree.h"
#include "..\DataManager\CategoryManager.h"
#include "..\DataManager\PasswordManager.h"


class IPswCateCallback
{
public:
	virtual void OnClickPassword(int nID) = 0;
};



class CPasswordCategoryTree
	: public CKnowlTypeTree
{
public:
	DECLARE_WND_CLASS(_T("CPasswordCategoryTree"))
	CPasswordCategoryTree(){
		
	}
	void SetPswCallback(IPswCateCallback* callback)
	{
		m_ArtCallback = callback;
	}
	BOOL Load(int nMasterId)
	{
		
		return m_CateManager.Load(this,L"PSW",nMasterId);
	}
	virtual void AcceptDrag(HTREEITEM hItem,int nID)
	{
		CPasswordManager art;
		int nClassID = (int)GetItemData(hItem);
		art.MoveTo(nClassID,nID);
	}
protected:
	IPswCateCallback*		m_ArtCallback;
	CCategoryManager		m_CateManager;
	
	virtual LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		POINT pt = {LOWORD(lParam), HIWORD(lParam)}; 
		HTREEITEM hTreeItem = HitTest(pt, &m_uClickFlags);
		if (hTreeItem != NULL)
		{
			int nID = (int)GetItemData(hTreeItem);
			if(NULL != m_ArtCallback)
				m_ArtCallback->OnClickPassword(nID);
		}
		return __super::OnLButtonDown(uMsg,wParam,lParam,bHandled);

	}
	virtual void OnItemDrag(HTREEITEM itemSrc,HTREEITEM itemDst)
	{
		if(NULL == itemSrc || NULL == itemDst)
			return;
		int classid = (int)GetItemData(itemSrc);
		int parent = (int)GetItemData(itemDst);
		m_CateManager.ChangeParent(parent,classid);
	}
public:
	/*BEGIN_MSG_MAP(CArticleCategoryTree)

        MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)

    END_MSG_MAP()*/

};